package com.edu.buservice.web.controller;

import com.edu.buservice.biz.TenantManger;
import com.edu.buservice.biz.model.Request.TenantRequest;
import com.edu.buservice.util.model.PageQuery;
import com.edu.buservice.util.model.R;
import com.edu.buservice.util.model.TenantUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @program: KQAIA
 * @description:
 * @author: 无恙
 * @create: 2025-04-13 18:42
 **/

@RestController
@RequestMapping("/buservice/tenant")
@Slf4j
public class TenantController {

	@Autowired
	private TenantManger tenantManger;

	/*
	* @author 范铁凝
	* @date 2025/4/13
	* 新建租户
	*/
	@RequestMapping("/addTenant")
	public R<?> addTenant(@RequestBody @Validated TenantRequest tenantRequest){

		log.info("TenantController addTenant:{}",tenantRequest);
		return R.success(tenantManger.addTenant(tenantRequest));
	}

	/*
	* @author 范铁凝
	* @date 2025/4/13
	* 分页查询租户
	*/
	@RequestMapping("/list")
	public R<?> queryTenant(@RequestBody @Validated PageQuery<TenantRequest> tenantRequest){

		log.info("TenantController queryTenant:{}",tenantRequest);
		return R.success(tenantManger.queryTenantInfo(tenantRequest));
	}

	/*
	* @author 范铁凝
	* @date 2025/4/13
	* 删除租户
	*/
	@DeleteMapping("/delete/{id}")
	public R<?> deleteTenant(@PathVariable("id") String id){

		log.info("TenantController deleteTenant:{}",id);
		return R.success(tenantManger.deleteTenant(id));
	}

	/*
	* @author 范铁凝
	* @date 2025/4/14
	* 编辑租户
	*/
	@RequestMapping("/editTenant")
	public R<?> editTenant(@RequestBody @Validated TenantRequest tenantRequest){

		log.info("TenantController editTenant:{}",tenantRequest);
		return R.success(tenantManger.editTenant(tenantRequest));
	}

	/*
	* @author 范铁凝
	* @date 2025/4/14
	* 更新租户状态
	*
	*/
	@RequestMapping("/updateStatus")
	public R<?> updateStatus(@RequestBody @Validated TenantRequest tenantRequest){

		log.info("TenantController updateStatus:{}",tenantRequest);
		return R.success(tenantManger.updateStatus(tenantRequest));
	}

	/*
	* @author 范铁凝
	* @date 2025/4/14
	* 获取当前租户信息
	*
	*/
	@RequestMapping("/current")
	public R<?> getCurrentTenantInfo(){

		log.info("TenantController getCurrentTenantInfo");
		return R.success(tenantManger.getTenantInfoByTenantId(TenantUtil.getTenantId()));
	}
}
